home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’87 / Source ƒ.sit / Source ƒ / C ƒ / TRANS-LSC / MultiSkel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-10-24  |  4.4 KB  |  224 lines  |  [TEXT/KAHL]

  1. /*
  2.     TransSkel multiple-window demonstration: main module
  3.  
  4.     This module performs setup and termination operations, installs
  5.     the window and menu handlers, and processes menu item selections.
  6.     
  7.     There are four window handlers in this demonstration.  The code
  8.     for each handler is in its own module.
  9.     
  10.     Help Window        Scrollable non-editable text window
  11.     Edit Window        Non-scrollable editable text window
  12.     Zoom Window        Non-manipulable graphics display window
  13.     Region Window    Manipulable graphics display window
  14.  
  15.     The project should include MacTraps, TransSkel.c (or a project built
  16.     from TransSkel.c), MSkelHelp.c, MSkelEdit.c, MSkelZoom.c and
  17.     MSkelRgn.c.  You'll also need the MultiSkel.h header file.
  18.  
  19.     24 June 1986        Paul DuBois
  20. */
  21.  
  22. # include    "MultiSkel.h"
  23.  
  24.  
  25. /* file menu item numbers */
  26.  
  27. typedef enum {
  28.     open = 1,
  29.     close,
  30.     /* --- */
  31.     quit = 4
  32. } fileItems;
  33.  
  34.  
  35. /*
  36.     Menu handles.  There isn't any apple menu here, since TransSkel will
  37.     be told to handle it itself.
  38. */
  39.  
  40. MenuHandle            fileMenu;
  41. MenuHandle            editMenu;
  42.  
  43. RgnHandle            oldClip;
  44.  
  45.  
  46. main ()
  47.  
  48. {
  49.     SkelInit ();
  50.     SetUpMenus ();            /* install menu handlers */
  51.     RgnWindInit ();            /* install window handlers  */
  52.     ZoomWindInit ();
  53.     EditWindInit ();
  54.     HelpWindInit ();
  55.     SkelMain ();
  56.     SkelClobber ();        /* throw away windows and menus */
  57. }
  58.  
  59.  
  60. /*
  61.     Initialize menus.  Tell Skel to process the Apple menu automatically,
  62.     and associate the proper procedures with the File and Edit menus.
  63. */
  64.  
  65. SetUpMenus ()
  66. {
  67. int        DoAbout(), DoFile(), DoEdit();
  68.  
  69.     SkelApple ("\pAbout MultiSkel…", &DoAbout);
  70.     fileMenu = GetMenu (fileMenuRes);
  71.     editMenu = GetMenu (editMenuRes);
  72.     SkelMenu (fileMenu, &DoFile, nil);
  73.     SkelMenu (editMenu, &DoEdit, nil);
  74. }
  75.  
  76.  
  77. /*
  78.     Handle selection of About MultiSkel… item from Apple menu
  79. */
  80.  
  81. DoAbout ()
  82. {
  83.     (void) Alert (aboutAlrt, nil);
  84. }
  85.  
  86.  
  87. /*
  88.     Process selection from File menu.
  89.     
  90.     Open    Make all four windows visible
  91.     Close    Hide the frontmost window.  If it belongs to a desk accessory,
  92.             close the accessory.
  93.     Quit    Request a halt by calling SkelHalt().  This makes SkelMain
  94.             return.
  95. */
  96.  
  97. DoFile (item)
  98. int        item;
  99. {
  100. WindowPeek    wPeek;
  101.  
  102.     switch (item)
  103.     {
  104.         case open:
  105.         {
  106.             MyShowWindow ((WindowPeek) rgnWind);
  107.             MyShowWindow ((WindowPeek) zoomWind);
  108.             MyShowWindow ((WindowPeek) editWind);
  109.             MyShowWindow ((WindowPeek) helpWind);
  110.             break;
  111.         }
  112. /*
  113.     Close the front window.  Take into account whether it belongs
  114.     to a desk accessory or not.
  115. */
  116.         case close:
  117.         {
  118.             if ((wPeek = (WindowPeek) FrontWindow ()) != nil)
  119.             {
  120.                 if (wPeek->windowKind < 0)
  121.                     CloseDeskAcc (wPeek->windowKind);
  122.                 else
  123.                     HideWindow (FrontWindow ());
  124.             }
  125.             break;
  126.         }
  127.         case quit:
  128.         {
  129.             SkelWhoa ();        /* request halt */
  130.             break;
  131.         }
  132.     }
  133. }
  134.  
  135.  
  136. /*
  137.     Show a window if it's not visible.  Select the window FIRST, then
  138.     show it, so that it comes up in front.  Otherwise it will be drawn
  139.     in back then brought to the front, which is ugly.
  140.  
  141.     The test for visibility must be done carefully:  the window manager
  142.     stores 255 and 0 for true and false, not real boolean values.
  143. */
  144.  
  145. MyShowWindow (wind)
  146. WindowPeek    wind;
  147. {
  148.  
  149.     if (wind->visible == 0)
  150.     {
  151.         SelectWindow (wind);
  152.         ShowWindow (wind);
  153.     }
  154. }
  155.  
  156.  
  157. /*
  158.     Process item selected from Edit menu.  First check whether it should
  159.     get routed to a desk accessory or not.  If not, then for route the
  160.     selection to the text editing window, as that is the only one for
  161.     this application to which edit commands are valid.
  162.     (The test of FrontWindow is not strictly necessary, as the Edit
  163.     menu is disabled when any of the other windows is frontmost, and so
  164.     this Proc couldn't be called.)
  165. */
  166.  
  167. DoEdit (item)
  168. int         item;
  169. {
  170.     if (!SystemEdit (item - 1))        /* check DA edit choice */
  171.     {
  172.         if (FrontWindow () == editWind)
  173.             EditWindEditMenu (item);
  174.     }
  175. }
  176.  
  177.  
  178. /*
  179.     Miscellaneous routines
  180.     These take care of drawing the grow box and the line along
  181.     the right edge of the window, and of setting and resetting the clip
  182.     region to disallow drawing in that right edge by the other drawing
  183.     routines.
  184. */
  185.  
  186.  
  187. DrawGrowBox (wind)
  188. WindowPtr    wind;
  189.  
  190. {
  191. Rect        r;
  192. RgnHandle    oldClip;
  193.  
  194.     r = wind->portRect;
  195.     r.left = r.right - 15;        /* draw only along right edge */
  196.     oldClip = NewRgn ();
  197.     GetClip (oldClip);
  198.     ClipRect (&r);
  199.     DrawGrowIcon (wind);
  200.     SetClip (oldClip);
  201.     DisposeRgn (oldClip);
  202. }
  203.  
  204.  
  205. SetWindClip (wind)
  206. WindowPtr    wind;
  207.  
  208. {
  209. Rect        r;
  210.  
  211.     r = wind->portRect;
  212.     r.right -= 15;        /* don't draw along right edge */
  213.     oldClip = NewRgn ();
  214.     GetClip (oldClip);
  215.     ClipRect (&r);
  216. }
  217.  
  218.  
  219. ResetWindClip ()
  220. {
  221.     SetClip (oldClip);
  222.     DisposeRgn (oldClip);
  223. }
  224.